/* SimplePodBooking.java - A pod booking auto generator.
 * shengyi_chen@symantec.com
 * 
 * This is a simple work tool. It is designed to simplify our work progress.
 * 
 * You'll need 3rd part libraries to compile this tool.
 * - poi: the Java API for Microsoft Documents documents API, @see http://poi.apache.org  
 * - JCalender: a free, simple java calendar picker, @see http://toedter.com/en/jcalendar/index.html
 * */

import javax.swing.JComponent;
import javax.swing.JFrame;

import services.DataCache;
import services.DataCache.eDataSections;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Color;

/**
 * A JFrame window class. It shows a splash screen and does some data loading in background.
 *  
 */

public class SimplePodBooking extends JFrame implements Runnable{
	private static final long serialVersionUID = -4324021764324361538L;
	private LaunchPad launchPad;
	/**
	 * create a splash screen.
	 */
	public SimplePodBooking()
	{
		setSize(600,200);
		setUndecorated(true);
		
		//Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		int w = getSize().width;
	    int h = getSize().height;
	    int x = (DataCache.screenDim.width-w)/2;
	    int y = (DataCache.screenDim.height-h)/2;
	    setLocation(x, y);

        launchPad = new LaunchPad();
        Font ft = new Font(Font.DIALOG, 0, 45);
        
        launchPad.setFont(ft);        
        launchPad.setBackground(Color.black);

        getContentPane().add(BorderLayout.CENTER, launchPad);
        setVisible(true);
	}
	public static void main(String[] args) {
		SimplePodBooking spb = new SimplePodBooking();
		Thread tSPB = new Thread(spb);
		tSPB.start();		
	}
	@Override
	/**
	 * load settings. Then create the main frame window, StartScreen.
	 * @see java.lang.Runnable#run()
	 * @see view.StartScreen()
	 */
	public void run() {		
		DataCache.reloadData(eDataSections.Configuration);
		DataCache.reloadData(eDataSections.CourseMatrix);
		DataCache.reloadData(eDataSections.VAMatrix);
		DataCache.reloadData(eDataSections.PBTemplate);
		DataCache.reloadData(eDataSections.Dictionary);
		DataCache.reloadData(eDataSections.NAM);
		DataCache.reloadData(eDataSections.ROW);
		setVisible(false);
		
		view.StartScreen frameSS = new view.StartScreen();
		frameSS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		int sX = getLocation().x;
	    int sY = getLocation().y;
	    int x = sX - frameSS.getSize().width;
	    int y = sY - frameSS.getSize().height;
	    frameSS.setLocation(x, y);
		Thread tframeSS = new Thread(frameSS);
		tframeSS.start();
	}

}

class LaunchPad extends JComponent {

   	private static final long serialVersionUID = -8149173987189218858L;
	/**
	 * get fixed size
	 * @see javax.swing.JComponent#getPreferredSize()
	 */
	public Dimension getPreferredSize() {
        return new Dimension(500,200);
    }

	/**
	 * set font
	 * @see javax.swing.JComponent#setFont(java.awt.Font)
	 */
    public void setFont(Font font) {
        super.setFont(font);
        repaint();
    }
    /**
     * create a black box with white charactors.
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Color.white);
        g.setFont(getFont());
        FontMetrics metrics = g.getFontMetrics();
        String text = "Symantec Virtual Academy";
        int x = getWidth()/2 - metrics.stringWidth(text)/2;
        int y = getHeight() - 120;
        
        g.drawString(text, x, y);
        text = "Pod Booking Helper";
        g.drawString(text, x+80, y+80);
    }
}
